package cn.jxufe.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.jxufe.bean.EasyUIData;
import cn.jxufe.bean.EasyUIDataPageRequest;
import cn.jxufe.bean.Message;
import cn.jxufe.entity.Farm;
import cn.jxufe.entity.Seed;
import cn.jxufe.entity.User;
import cn.jxufe.service.FarmService;
import cn.jxufe.service.SeedService;

/***
 * 用户在游戏中的交互操作
 * @author Banner
 *
 */
@Controller
@RequestMapping("farm")
public class FarmController {
	@Autowired
    private FarmService farmService;
	
	/***
	 * 获取所欲的farm，即正在进行的游戏.
	 * @return farm列表
	 */
	@RequestMapping("list")
	public List<Farm> list() {
		return farmService.list();
	}
	
	/***
	 * 跳转到farm/game.jsp页面.
	 * @param session 请求
	 * @param model model
	 * @return String
	 */
	@RequestMapping("game")
	public String grid(HttpSession session, Model model) {
		return "farm/game";
	}
	
	/***
	 * 保存farm信息.
	 * @param farm 游戏信息列表
	 */
	@RequestMapping("save")
	public void save(Farm farm) {
		farmService.save(farm);
		System.out.println("数据保存成功，farm Id = " + farm.getId());
	}
	
	/***
	 * 播种.
	 * @param landId 土地id
	 * @param seedId 种子id
	 * @param session 请求
	 * @return Message
	 */
	// 播种
	@RequestMapping("plant")
	@ResponseBody
	public Message actionPlant(int landId, int seedId, HttpSession session){
		return farmService.plant(landId, seedId, session);
	}
	
	/***
	 * 除虫.
	 * @param landId 土地id
	 * @param session 请求
	 * @return Message
	 */
	// 除虫
	@RequestMapping("killInsect")
	@ResponseBody
	public Message actionKillInsect(int landId, HttpSession session){
		return farmService.killInsect(landId, session);
	}
	
	// 收获
	/***
	 * 收获.
	 * @param landId 土地id
	 * @param session 请求
	 * @return Message
	 */
	@RequestMapping("harvest")
	@ResponseBody
	public Message actionHarvest(int landId, HttpSession session){
		return farmService.harvest(landId, session);
	}
	
	/***
	 * 除枯草.
	 * @param landId 种子id
	 * @param session 请求
	 * @return Message
	 */
	// 除枯草
	@RequestMapping("cleanLand")
	@ResponseBody
	public Message actionCleanLand(int landId, HttpSession session){
		return farmService.cleanLand(landId, session);
	}
	
	/***
	 * 产量提升.
	 * @param landId 种子id
	 * @param session 请求
	 * @return Message
	 */
	// 提升产量
	@RequestMapping("addHarvest")
	@ResponseBody
	public Message addHarvest(int landId, HttpSession session){
		return farmService.addHarvest(landId, session);
	}
}
